﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;

namespace DALL.SysManage
{
    public class THEME_PROJECT
    {
        public THEME_PROJECT()
        { }

        /// <summary>
        /// 获得数据列表（比DataSet效率高，推荐使用）
        /// </summary>
        public List<Model.SysManage.THEME_PROJECT> GetProjectList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select id,OriderID,ProjectID,PROJECT_NAME,Number,PRICE,REMARK ");
            strSql.Append(" FROM THEME_PROJECT ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<Model.SysManage.THEME_PROJECT> list = new List<Model.SysManage.THEME_PROJECT>();
            Database db = DatabaseFactory.CreateDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                while (dataReader.Read())
                {
                    list.Add(ReaderBind(dataReader));
                }
            }
            return list;
        }

        #region  Method
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.SysManage.THEME_PROJECT GetModel(int id, string OriderID, string ProjectID, string PROJECT_NAME, int Number, int PRICE, string REMARK)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select id,OriderID,ProjectID,PROJECT_NAME,Number,PRICE,REMARK from THEME_PROJECT ");
            strSql.Append(" where id=@id and OriderID=@OriderID and ProjectID=@ProjectID and PROJECT_NAME=@PROJECT_NAME and Number=@Number and PRICE=@PRICE and REMARK=@REMARK ");
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "id", DbType.Int32, id);
            db.AddInParameter(dbCommand, "OriderID", DbType.String, OriderID);
            db.AddInParameter(dbCommand, "ProjectID", DbType.String, ProjectID);
            db.AddInParameter(dbCommand, "PROJECT_NAME", DbType.String, PROJECT_NAME);
            db.AddInParameter(dbCommand, "Number", DbType.Int32, Number);
            db.AddInParameter(dbCommand, "PRICE", DbType.Int32, PRICE);
            db.AddInParameter(dbCommand, "REMARK", DbType.String, REMARK);
            Model.SysManage.THEME_PROJECT model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select id,OriderID,ProjectID,PROJECT_NAME,Number,PRICE,REMARK ");
            strSql.Append(" FROM THEME_PROJECT ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            Database db = DatabaseFactory.CreateDatabase();
            return db.ExecuteDataSet(CommandType.Text, strSql.ToString());
        }

        /// <summary>
        /// 获得数据列表（比DataSet效率高，推荐使用）
        /// </summary>
        public List<Model.SysManage.THEME_PROJECT> GetListArray(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select id,OriderID,ProjectID,PROJECT_NAME,Number,PRICE,REMARK ");
            strSql.Append(" FROM THEME_PROJECT ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<Model.SysManage.THEME_PROJECT> list = new List<Model.SysManage.THEME_PROJECT>();
            Database db = DatabaseFactory.CreateDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                while (dataReader.Read())
                {
                    list.Add(ReaderBind(dataReader));
                }
            }
            return list;
        }


        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public Model.SysManage.THEME_PROJECT ReaderBind(IDataReader dataReader)
        {
            Model.SysManage.THEME_PROJECT model = new Model.SysManage.THEME_PROJECT();
            object ojb;
            ojb = dataReader["id"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.id = (int)ojb;
            }
            model.OriderID = dataReader["OriderID"].ToString();
            model.ProjectID = dataReader["ProjectID"].ToString();
            model.PROJECT_NAME = dataReader["PROJECT_NAME"].ToString();
            ojb = dataReader["Number"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Number = (int)ojb;
            }
            ojb = dataReader["PRICE"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.PRICE = (int)ojb;
            }
            model.REMARK = dataReader["REMARK"].ToString();
            return model;
        }

        #endregion  Method
    }
}
